Inside Macintosh: More Macintosh Toolbox

Previous | Chapter Top | Chapter Contents | Next

Registering Components

Before a component can be used by an application, the component must be registered with the Component Manager. The Component Manager automatically registers component resources stored in files with file types of 'thng' that are stored in the Extensions folder (for information about the content of component resources, see "Resources," ).

Alternatively, you can use either the RegisterComponent function or the RegisterComponentResource function to register components. Both applications and components can use these routines to register components.

Furthermore, you can use the RegisterComponentResourceFile function to register all components specified in a given resource file.

Once you have registered your component, applications can find the component and retrieve information about it using the Component Manager routines described earlier in this chapter in "Routines for Applications," .

Finally, you can use the UnregisterComponent function to remove a component from the registration list.

When an application quits, the Component Manager automatically closes any component connections to that application. In addition, if the application has registered components that reside in its heap space, the Component Manager automatically unregisters those components.

RegisterComponent

The RegisterComponent function makes a component available for use by applications (or other clients). Once the Component Manager has registered a component, applications can find and open the component using the standard Component Manager routines. To register a component, you provide information identifying the component and its capabilities. The Component Manager returns a component identifier that uniquely identifies the component to the system.

Components you register with the RegisterComponent function must be in memory when you call this function. If you want to register a component that is stored in the resource fork of a file, use the RegisterComponentResource function. Use the RegisterComponentResourceFile function to register all components in the resource fork of a file.

Note that a component residing in your application heap remains registered until your application unregisters it or quits. A component residing in the system heap and registered by your application remains registered until your application unregisters it or until the computer is shut down.

FUNCTION RegisterComponent (cd: ComponentDescription;
                                          componentEntryPoint: ComponentRoutine;
                                          global: Integer;
                                          componentName: Handle;
                                          componentInfo: Handle;
                                          componentIcon: Handle): Component;
cd
A component description record that describes the component to be registered. You must correctly fill in the fields of this record before calling the RegisterComponent function. When applications search for components using the FindNextComponent function, the Component Manager compares the attributes you specify here with those specified by the application. If the attributes match, the Component Manager returns the component identifier to the application.
componentEntryPoint
The address of the main entry point of the component you are registering. The routine referred to by this parameter receives all requests for the component.
global
A set of flags that control the scope of component registration. You can use these flags to specify a value for the global parameter:
registerCmpGlobal = 1;
Specify this flag to indicate that this component should be made available to other applications and clients as well as the one performing the registration. If you do not specify this flag, the component is available for use only by the registering application or component (that is, the component is local to the A5 world of the registering program).
registerCmpNoDuplicates = 2;
Specify this flag to indicate that if a component with identical characteristics to the one being registered already exists, then the new one should not be registered ( RegisterComponent returns 0 in this situation). If you do not specify this flag, the component is registered even if a component with identical characteristics to the one being registered already exists.
registerCompAfter = 4;
Specify this flag to indicate that this component should be registered after all other components with the same component type. Usually components are registered before others with identical descriptions; specifying this flag overrides that behavior.
componentName
A handle to the component's name. Set this parameter to NIL if you do not want to assign a name to the component.
componentInfo
A handle to the component's information string. Set this parameter to NIL if you do not want to assign an information string to the component.
componentIcon
A handle to the component's icon (a 32-by-32 pixel black-and-white icon). Set this parameter to NIL if you do not want to supply an icon for this component. Note that this icon is not used by the Finder; you supply an icon only so that other components or applications can display your component's icon if needed.

DESCRIPTION

The RegisterComponent function registers the specified component, recording the information specified in the cd , componentName , componentInfo , and componentIcon parameters. The function returns the component identifier assigned to the component by the Component Manager. If it cannot register the component, the RegisterComponent function returns a function result of NIL .

SEE ALSO

For a complete description of the component description record, see "Data Structures for Components," .

RegisterComponentResource

The RegisterComponentResource function makes a component available for use by applications (or other clients). Once the Component Manager has registered a component, applications can find and open the component using the standard Component Manager routines. You provide information identifying the component and specifying its capabilities. The Component Manager returns a component identifier that uniquely identifies the component to the system.

Components you register with the RegisterComponentResource function must be stored in a resource file as a component resource (see "The Component Resource," for a description of the format and content of component resources). If you want to register a component that is in memory, use the RegisterComponent function.

The RegisterComponentResource function does not actually load the code specified by the component resource into memory. Rather, the Component Manager loads the component code the first time an application opens the component. If the code is not in the same file as the component resource or if the Component Manager cannot find the file, the open request fails.

Note that a component registered locally by your application remains registered until your application unregisters it or quits. A component registered globally by your application remains registered until your application unregisters it or until the computer is shut down.

FUNCTION RegisterComponentResource (cr: ComponentResourceHandle;
                                         global: Integer): Component;
cr
A handle to a component resource that describes the component to be registered. The component resource contains all the information required to register the component.
global
A set of flags that controls the scope of component registration. You can use these flags to specify a value for the global parameter:
registerCmpGlobal = 1;
Specify this flag to indicate that this component should be made available to other applications and clients as well as the one performing the registration. If you do not specify this flag, the component is available for use only by the registering application or component (that is, the component is local to the A5 world of the registering program).
registerCmpNoDuplicates = 2;
Specify this flag to indicate that if a component with identical characteristics to the one being registered already exists, then the new one should not be registered ( RegisterComponentResource returns 0 in this situation). If you do not specify this flag, the component is registered even if a component with identical characteristics to the one being registered already exists.
registerCompAfter = 4;
Specify this flag to indicate that this component should be registered after all other components with the same component type. Usually components are registered before others with identical descriptions; specifying this flag overrides that behavior.

DESCRIPTION

The RegisterComponentResource function returns the component identifier assigned to the component by the Component Manager. If the RegisterComponentResource function could not register the component, it returns a function result of NIL .

SEE ALSO

For a description of the format and content of component resources, see "Resources," .

RegisterComponentResourceFile

The RegisterComponentResourceFile function registers all component resources in the given resource file according to the flags specified in the global parameter.

FUNCTION RegisterComponentResourceFile (resRefNum: integer;
                                          global: integer): LongInt;
resRefNum
The reference number of the resource file containing the components to register.
global
A set of flags that control the scope of the registration of the components in the resource file specified in the resRefNum parameter. You can use these flags to specify a value for the global parameter:
registerCmpGlobal = 1;
Specify this flag to indicate that each component in the resource file should be made available to other applications and clients as well as the one performing the registration. If you do not specify this flag, each component is available for use only by the registering application or component (that is, the component is local to the A5 world of the registering program).
registerCmpNoDuplicates = 2;
Specify this flag to indicate that if a component with identical characteristics to the one being registered already exists, then the new one should not be registered ( RegisterComponentResourceFile returns 0 in this situation). If you do not specify this flag, the component is registered even if a component with identical characteristics to the one being registered already exists.
registerCompAfter = 4;
Specify this flag to indicate that as RegisterComponentResourceFile registers a component, it should register the component after all other components with the same component type. Usually components are registered before others with identical descriptions; specifying this flag overrides that behavior.

DESCRIPTION

The RegisterComponentResourceFile function registers components in a resource file. If the RegisterComponentResourceFile function successfully registers all components in the specified resource file, RegisterComponentResourceFile returns a function result that indicates the number of components registered. If the RegisterComponentResourceFile function could not register one or more of the components in the resource file or if the specified file reference number is invalid, it returns a negative function result.

SEE ALSO

For a description of the format and content of component resources, see "Resources," .

UnregisterComponent

The UnregisterComponent function removes a component from the Component Manager's registration list. Most components are registered at startup and remain registered until the computer is shut down. However, you may want to provide some services temporarily. In that case you dispose of the component that provides the temporary service by using this function.

FUNCTION UnregisterComponent (aComponent: Component): OSErr;
aComponent
A component identifier that specifies the component to be removed. Applications that register components may obtain this identifier from the RegisterComponent or RegisterComponentResource functions.

DESCRIPTION

The UnregisterComponent function removes the component with the specified component identifier from the list of available components. The component to be removed from the registration list must not be in use by any applications or components. If there are open connections to the component, the UnregisterComponent function returns a negative result code.

RESULT CODES

noErr

0

No error

invalidComponentID

-3000

No component with this component identifier

validInstancesExist

-3001

This component has open connections

SEE ALSO

If you provide a component that supports the unregister request, see "Responding to the Register Request" for more information.


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next